package com.platform.mobile.operator;

import java.util.LinkedHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.platform.base.SysException;
import com.platform.mobile.bean.DoctorBean;
import com.platform.mobile.bean.ReqBean;
import com.platform.mobile.bean.ResBean;
import com.platform.mobile.bean.ResultBean;
import com.platform.mobile.factory.Operator;
import com.platform.mobile.service.DatasourceService;

@Component
public class DatasourceDoctor extends Operator{

	private static Logger log = LoggerFactory.getLogger(DatasourceDoctor.class);
	
	@Autowired
	private DatasourceService service;
	
	@Override
	public ResBean operate(ReqBean reqBean) throws SysException {
		
		log.info("进入到DatasourceDoctor业务处理类，处理[" + reqBean.getClientInfo() + "]用户请求");
		ResBean resBean = new ResBean();
		resBean.setClientInfo(reqBean.getClientInfo());
		resBean.setJsonrpc("2.0");
		resBean.setMethod("DatasourceDept");
		ResultBean result = new ResultBean();
		
		try{
			
			Object params = reqBean.getParams();
			if(params != null){
				
				@SuppressWarnings("unchecked")
				LinkedHashMap<String, Object> paramMap = (LinkedHashMap<String, Object>)params;
				Integer org_id = (Integer)paramMap.get("dept_id");
				
				DoctorBean doctorBean = service.getDoctorDatasource(org_id);
				if(doctorBean == null){ 
					result.setData(null);
					result.setInfo("获取医生数据源失败，部门ID为：" + org_id);
					result.setResultStatus("0");
				} else {
					result.setData(doctorBean);
					result.setInfo("获取医生数据源成功，部门ID为：" + org_id);
					result.setResultStatus("1");
				}
			}
			
		}catch(Exception e){
			e.printStackTrace();
			result.setData(null);
			result.setInfo("服务器异常");
			result.setResultStatus("0");
		}
		
		resBean.setResult(result);
		return resBean;
	}
}
